package cn.edu.pku.ss.music.net;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;

import android.os.AsyncTask;

public class LoginTask extends AsyncTask<String, Void, Integer> {
	
	@Override
	protected Integer doInBackground(String... params) {
		HttpClient client = SingletonHttpClient.getInstance();
		HttpPost post = new HttpPost(params[0]);
		
		List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
		postParameters.add(new BasicNameValuePair("username",params[1]));
		postParameters.add(new BasicNameValuePair("password",params[2]));
		
		HttpResponse response = null;
		try {
			System.out.println("client:"+client);
			System.out.println("post:"+post);
			post.setEntity(new UrlEncodedFormEntity(postParameters));
			response = client.execute(post);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
}
